import { Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { UiService } from '../../ui.service';
import { GB } from '../../../environments/environment';
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
import { I18nService } from '../../core/i18n/i18n.service';
import { ActionSheetConfig, SkinType, ActionSheetComponent, ActionSheetService, RatingConfig, PickerService, DatePickerComponent, PickerComponent } from 'ngx-weui';
import { MessageService } from './../../core/message.service';
import { InfiniteLoaderComponent, InfiniteLoaderConfig } from 'ngx-weui/infiniteloader';
import { ApiService } from 'src/app/core/api';
import { ActivatedRoute, Router } from '@angular/router';
import { FormBuilder, Validators, FormGroup } from '@angular/forms';
import { StorageService } from 'src/app/core/sotrage/storage.service';

@Component({
  templateUrl: './index.component.html',
  styleUrls: ['./index.component.less'],
  encapsulation: ViewEncapsulation.None,
})
export class WalletTansferComponent implements OnInit {

  investForm: FormGroup;
  titel = '';
  radio = [
    { id: 1, name: 'USDT', img: '../../../assets/images/invest-page/USDT.png' },
    { id: 2, name: 'VISA', img: '../../../assets/images/invest-page/visa.png' },
    { id: 3, name: 'Jcash', img: '../../../assets/images/invest-page/Jcash.png' }
  ];
  list;
  listNames = [];
  radioType;
  msgData;
  selitem;
  pickOpt = {
    cancel:'取消',
    confirm:'确定'
  };

  constructor(
    private i: I18nService,
    private api: ApiService,
    private sto: StorageService,
    private route: ActivatedRoute,
    private router: Router,
    private fb: FormBuilder,
    private srv: PickerService,

  ) {
  }
  ngOnInit() {
    this.getPayList();
    this.investForm = this.fb.group(
      {
        value: [null, [Validators.required]]
      }
    );
    this.i.get([
      'websiteRedeploy.html7',
      // 'InvestBalance-Page.radio2'
    ]).subscribe(res => {
      this.msgData = res;
      this.titel = this.msgData['websiteRedeploy.html7'];
    });
  };

  getPayList() {
    //暂时没有
    // this.api.post('支付方式列表',{}).then((e: any) => {
    // });
    this.api.post('用户各游戏内钱包余额列表', { pageNo: 1 }).then((e: any) => {
      this.list = e['data']['list'];
      this.selitem = this.list[0];
      for (let i = 0; i < this.list.length; i++) {
        this.listNames.push(this.list[i].providerName) ;
      }
    });
  }
  dialogShow = false;
  isError = true;
  isClickPay = true;
  toPay(form) {
    let data = form.value;
    data.type = "deposit" ;
    data.providerId = this.selitem.providerId ;
    
    if (form.valid && this.isClickPay) {
      this.isClickPay = false;
      this.api.post('账号金额变更[上游平台]', data).then((res: any) => {
        this.isClickPay = true;
        this.dialogShow = true;
        if (res.status == 0) {
          this.isError = false;
        } else {
          this.isError = true;
        }
      });
    }
  };
  onOutsize(bool) {
    this.dialogShow = bool;
  }
  chickOut() {
    this.dialogShow = false;
  }
  cancel() {
    this.dialogShow = false;
  }
  showlist(){
    this.srv.show(this.listNames, this.listNames[0], [] , this.pickOpt ).subscribe((res: any) => {
     console.log(res)
     for (let i = 0; i < this.list.length; i++) {
       const element = this.list[i];
       if(element.providerName == res.value){
         this.selitem = element;
       }
       
     }
    });
  }

}
